package org.jeecg.modules.hotel.arrangement.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.apache.shiro.SecurityUtils;
import org.jeecg.common.system.api.ISysBaseAPI;
import org.jeecg.common.system.vo.LoginUser;
import org.jeecg.common.util.oConvertUtils;
import org.jeecg.modules.basic.demo.apartment.entity.LwgyBaseApartment;
import org.jeecg.modules.basic.demo.apartment.entity.LwgyRoomViews;
import org.jeecg.modules.basic.demo.apartment.mapper.LwgyBaseApartmentMapper;
import org.jeecg.modules.basic.demo.apartment.service.ILwgyRoomViewsService;
import org.jeecg.modules.basic.demo.bed.entity.LwgyBaseBed;
import org.jeecg.modules.basic.demo.bed.entity.LwgyBedAssignment;
import org.jeecg.modules.basic.demo.bed.mapper.LwgyBaseBedMapper;
import org.jeecg.modules.basic.demo.bed.service.ILwgyBaseBedService;
import org.jeecg.modules.basic.demo.student.entity.LwgyBaseStudent;
import org.jeecg.modules.basic.demo.student.service.ILwgyBaseStudentService;
import org.jeecg.modules.hotel.arrangement.entity.*;
import org.jeecg.modules.hotel.arrangement.mapper.LwgyHotelArrangementMapper;
import org.jeecg.modules.hotel.arrangement.service.ILwgyHotelArrangementService;
import org.jeecg.modules.hotel.history.entity.LwgyHotelHistory;
import org.jeecg.modules.hotel.history.service.ILwgyHotelHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

@Service
public class LwgyHotelArrangementServiceImpl extends ServiceImpl<LwgyHotelArrangementMapper, LwgyHotelArrangement> implements ILwgyHotelArrangementService {

    @Resource
    private LwgyHotelArrangementMapper lwgyHotelArrangementMapper;

    @Resource
    private LwgyBaseBedMapper lwgyBaseBedMapper;

    @Resource
    private ILwgyBaseStudentService lwgyBaseStudentService;

    @Autowired
    private ILwgyBaseBedService lwgyBaseBedService;
    @Autowired
    private ILwgyRoomViewsService lwgyRoomViewsService;

    @Resource
    private LwgyBaseApartmentMapper lwgyBaseApartmentMapper;

    @Autowired
    private ILwgyHotelHistoryService lwgyHotelHistoryService;

    @Autowired
    private ISysBaseAPI sysBaseAPI;

    @Autowired
    private ILwgyHotelArrangementService lwgyHotelArrangementService;

    @Override
    public void checkOutStu(LwgyHotelArrangement lwgyHotelArrangement) {
        lwgyHotelArrangementMapper.checkOutStu(lwgyHotelArrangement);
    }

    @Override
    public void updateBedStu(LwgyHotelArrangement lwgyHotelArrangement) {
        lwgyHotelArrangementMapper.updateBedStu(lwgyHotelArrangement);
    }

    @Override
    public void cleanBed(String ids) {
        List<String> strings = Arrays.asList(ids.split(","));
        List<LwgyBaseBed> list = new ArrayList<>();
        for (String string : strings) {
            LwgyBaseBed lwgyBaseBed = new LwgyBaseBed();
            lwgyBaseBed.setId(string);
            lwgyBaseBed.setStudentId("");
            list.add(lwgyBaseBed);
            System.out.println(list.size());
        }
        int cleanList = list.size();
        int i = 0;
        while(cleanList > 500){
            lwgyBaseBedService.updateBatchById(list.subList(i,i + 500));
            i = i + 500;
            cleanList = list.size() - i;
        }
        if(cleanList > 0){
            lwgyBaseBedService.updateBatchById(list.subList(i,i + cleanList));
        }
    }
    @Override
    public void cleanHolidayBed(String ids) {
        List<String> strings = Arrays.asList(ids.split(","));
        List<LwgyBaseBed> list = new ArrayList<>();
        for (String string : strings) {
            LwgyBaseBed lwgyBaseBed = new LwgyBaseBed();
            lwgyBaseBed.setId(string);
            lwgyBaseBed.setHolidayStudentId("");
            list.add(lwgyBaseBed);
            System.out.println(list.size());
        }
        int cleanList = list.size();
        int i = 0;
        while(cleanList > 500){
            lwgyBaseBedService.updateBatchById(list.subList(i,i + 500));
            i = i + 500;
            cleanList = list.size() - i;
        }
        if(cleanList > 0){
            lwgyBaseBedService.updateBatchById(list.subList(i,i + cleanList));
        }
    }


  /*  public void automaticStu(String ids) {

        List<LwgyBaseBed> bedList = new ArrayList<>();//床位集合
        List<LwgyBaseBed> studentList = new ArrayList<>();//学生集合
        if (bedList.size() >= studentList.size()) {
            for (int i = 0; i < bedList.size(); i++) {
                LwgyBaseBed lwgyBaseBed = bedList.get(i);
                LwgyBaseBed lwgyBaseBed1 = studentList.get(i);
                lwgyBaseBed.setStudentId(lwgyBaseBed1.getstudentId());
            }
        } else {
           *//* LwgyBaseBed lwgyBaseBed = bedList.get(0);
            LwgyBaseBed lwgyBaseBed1 = studentList.get(0);
            lwgyBaseBed.setStudentId(lwgyBaseBed1.getstudentId());*//*

        }

        lwgyBaseBedService.update(bedList);
    }
*/



    @Override
    public void batchAllot(Map<String, String> hotelArrange) {
        String bedIds = hotelArrange.get("bedIds");
        String adminId = hotelArrange.get("id");
        List<LwgyBaseBed> list = new ArrayList<>();
        List<String> strings = Arrays.asList(bedIds.split(","));
        for (String id : strings) {
            LwgyBaseBed lwgyBaseBed = new LwgyBaseBed();
            lwgyBaseBed.setId(id);
            lwgyBaseBed.setAdminId(adminId);
            list.add(lwgyBaseBed);
        }
        lwgyBaseBedService.updateBatchById(list);
    }

    @Override
    public void batchRecycle(String bedId) {
        List<LwgyBaseBed> list = new ArrayList<>();
        List<String> strings = Arrays.asList(bedId.split(","));
        for (String id : strings) {
            LwgyBaseBed lwgyBaseBed = new LwgyBaseBed();
            lwgyBaseBed.setId(id);
            lwgyBaseBed.setAdminId("");
            list.add(lwgyBaseBed);
        }
        lwgyBaseBedService.updateBatchById(list);
    }

    @Override
    public List<LwgyBaseBed> getBedListByStudentId(String studentId) {
        return lwgyHotelArrangementMapper.getBedListByStudentId(studentId);
    }

    @Override
    public boolean getClassOpenTime(String studentClass) {
        if (studentClass != null && !"".equals(studentClass)) {
            Integer count = lwgyHotelArrangementMapper.getClassOpenTime(studentClass);
            if(count>=1){
                return true;
            }
        }
        return false;
    }



    @Override
    public String getBuildId(String roomId) {
        QueryWrapper<LwgyRoomViews> wrapper = new QueryWrapper<>();
        wrapper.select("building_id");
        wrapper.eq("room_id",roomId);
        return lwgyRoomViewsService.getOne(wrapper).getBuildingId();
    }

    @Override
    public List<ImportStuHotel> outStuHotel(LwgyBaseBed lwgyBed) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<String> roles = sysBaseAPI.getRolesByUsername(sysUser.getUsername());
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        lwgyBaseApartment.setStudentCampus(lwgyBed.getStudentCampus());
        lwgyBaseApartment.setStudentCollege(lwgyBed.getStudentCollege());
        lwgyBaseApartment.setStudentYear(lwgyBed.getStudentYear());
        lwgyBaseApartment.setStudentMajor(lwgyBed.getStudentMajor());
        lwgyBaseApartment.setStudentClass(lwgyBed.getStudentClass());
        lwgyBaseApartment.setStudentEducation(lwgyBed.getStudentEducation());
        lwgyBaseApartment.setStudentLeaveschool(lwgyBed.getStudentLeaveschool());
        lwgyBaseApartment.setStudentSchoolSystem(lwgyBed.getStudentSchoolSystem());
        lwgyBaseApartment.setStudentLeaveschool_begin(lwgyBed.getStudentLeaveschool_begin());
        lwgyBaseApartment.setStudentLeaveschool_end(lwgyBed.getStudentLeaveschool_end());
        lwgyBaseApartment.setRoomSex(lwgyBed.getRoomSex());
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        List<ImportStuHotel>  list = lwgyHotelArrangementMapper.outStuHotel(lwgyBaseApartment);

        if (roles.contains("fdy")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        if (roles.contains("yanjiusheng")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        return list;

    }

    @Override
    public List<LwgyXyBedAssignment> outXyHotel(LwgyXyBedAssignment lwgyBed) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<String> roles = sysBaseAPI.getRolesByUsername(sysUser.getUsername());
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        lwgyBaseApartment.setIsAdminId(lwgyBed.getIsAdminId());
        lwgyBaseApartment.setIsBed(lwgyBed.getIsBed());
        lwgyBaseApartment.setRealname(lwgyBed.getRealname());
        lwgyBaseApartment.setStudentName(lwgyBed.getStudentName());
        lwgyBaseApartment.setStudentNumber(lwgyBed.getStudentNumber());
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        List<LwgyXyBedAssignment>  list = lwgyHotelArrangementMapper.outXyHotel(lwgyBaseApartment);

        if (roles.contains("fdy")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        return list;

    }

    @Override
    public List<StuHotelRoster> StuZsHotel(LwgyBaseBed lwgyBed) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<String> roles = sysBaseAPI.getRolesByUsername(sysUser.getUsername());
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        lwgyBaseApartment.setStudentCampus(lwgyBed.getStudentCampus());
        lwgyBaseApartment.setStudentCollege(lwgyBed.getStudentCollege());
        lwgyBaseApartment.setStudentYear(lwgyBed.getStudentYear());
        lwgyBaseApartment.setStudentMajor(lwgyBed.getStudentMajor());
        lwgyBaseApartment.setStudentClass(lwgyBed.getStudentClass());
        lwgyBaseApartment.setStudentEducation(lwgyBed.getStudentEducation());
        lwgyBaseApartment.setStudentLeaveschool(lwgyBed.getStudentLeaveschool());
        lwgyBaseApartment.setStudentSchoolSystem(lwgyBed.getStudentSchoolSystem());
        lwgyBaseApartment.setStudentLeaveschool_begin(lwgyBed.getStudentLeaveschool_begin());
        lwgyBaseApartment.setStudentLeaveschool_end(lwgyBed.getStudentLeaveschool_end());
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        List<StuHotelRoster>  list = lwgyHotelArrangementMapper.StuZsHotel(lwgyBaseApartment);

        if (roles.contains("fdy")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        return list;

    }

    @Override
    public List<ImportXyScore> outXyScore(LwgyBaseBed lwgyBed,String scaleBatches) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        List<ImportXyScore>  list = lwgyHotelArrangementMapper.outXyScore(lwgyBaseApartment,scaleBatches);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<String> roles = sysBaseAPI.getRolesByUsername(sysUser.getUsername());
        if (roles.contains("fdy")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        return list;

    }
    @Override
    public List<ImportTeacherScore> outTeacherScore(LwgyBaseBed lwgyBed) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        List<ImportTeacherScore>  list = lwgyHotelArrangementMapper.outTeacherScore(lwgyBaseApartment);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<String> roles = sysBaseAPI.getRolesByUsername(sysUser.getUsername());
        if (roles.contains("fdy")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        return list;

    }
    @Override
    public List<ImportTeacherScore> outTeacherScore1(LwgyBaseBed lwgyBed) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        List<ImportTeacherScore>  list = lwgyHotelArrangementMapper.outTeacherScore1(lwgyBaseApartment);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<String> roles = sysBaseAPI.getRolesByUsername(sysUser.getUsername());
        if (roles.contains("fdy")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        return list;

    }
    @Override
    public List<ImportScore> outScore(LwgyBaseBed lwgyBed, String scaleBatches) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        lwgyBaseApartment.setStudentCampus(lwgyBed.getStudentCampus());
        lwgyBaseApartment.setStudentCollege(lwgyBed.getStudentCollege());
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        List<ImportScore>  list = lwgyHotelArrangementMapper.outScore(lwgyBaseApartment,scaleBatches);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<String> roles = sysBaseAPI.getRolesByUsername(sysUser.getUsername());
        if (roles.contains("fdy")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        return list;

    }

    @Override
    public List<ImportStuHotel> outStuTemplate(LwgyBaseBed lwgyBed) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        List<ImportStuHotel>  list = lwgyHotelArrangementMapper.outStuHotel(lwgyBaseApartment);
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        List<String> roles = sysBaseAPI.getRolesByUsername(sysUser.getUsername());
        if (roles.contains("fdy")) {
            list = list.stream().filter(item->sysUser.getWorkNo().equals(item.getAdminId())).collect(Collectors.toList());
        }
        return list;

    }

    @Transactional(rollbackFor = Exception.class)
    @Override
    public void bedBatchBindTeacher(List<String> bedIds, String teacherIds,String facultyId) {
        LwgyBaseBed lwgyBaseBed;
        if(oConvertUtils.isNotEmpty(teacherIds)){
            String[] fields = teacherIds.split(",");
            if(oConvertUtils.listIsEmpty(Arrays.asList(fields))){
                teacherIds = "";
            }
        }
        if(oConvertUtils.isNotEmpty(facultyId)){
            String[] fields = facultyId.split(",");
            if(oConvertUtils.listIsEmpty(Arrays.asList(fields))){
                facultyId = "";
            }
        }

        List<LwgyBaseBed> lwgyBaseBeds = new ArrayList<>(bedIds.size());
        for (String bedId : bedIds) {
            lwgyBaseBed = new LwgyBaseBed();
            lwgyBaseBed.setId(bedId);
            lwgyBaseBed.setAdminId(teacherIds);
            lwgyBaseBed.setFacultyId(facultyId);
            lwgyBaseBeds.add(lwgyBaseBed);
        }
        lwgyBaseBedService.updateBatchById(lwgyBaseBeds);
    }

    @Override
    public void leaveSchool(String stuIds) {
        //学生id
        List<String> strings = Arrays.asList(stuIds.split(","));
        List<LwgyBaseStudent> list = new ArrayList<>();
        LwgyBaseStudent lwgyBaseStudent;
        for (String string : strings) {
            if(oConvertUtils.isNotEmpty(string)){
                lwgyBaseStudent = new LwgyBaseStudent();
                lwgyBaseStudent.setId(string);
                lwgyBaseStudent.setStudentState("1");
                list.add(lwgyBaseStudent);
            }
        }
        lwgyBaseStudentService.updateBatchById(list);
    }
    /*@Override
    public void leaveSchool(String stuIds) {
        //学生id
        List<String> strings = Arrays.asList(stuIds.split(","));
        //查询床位信息
        LambdaQueryWrapper<LwgyBaseBed> wrapper = new LambdaQueryWrapper<LwgyBaseBed>();
        wrapper.in(LwgyBaseBed::getStudentId,strings);
        List<LwgyBaseBed> lwgyBaseBedList = lwgyBaseBedService.list(wrapper);
        List<String> ids = lwgyBaseBedList.stream().map(LwgyBaseBed::getId).collect(Collectors.toList());
        lwgyHotelArrangementService.cleanBed(String.valueOf(ids));//批量清空住宿
        LoginUser sysUser = (LoginUser) SecurityUtils.getSubject().getPrincipal();
        //批量存储退宿记录
        List<LwgyHotelHistory> arrangementList = new ArrayList<>();
        for (LwgyBaseBed lwgyBaseBed : lwgyBaseBedList) {
            LwgyHotelHistory lwgyHotelHistory = new LwgyHotelHistory();
            lwgyHotelHistory.setPersonId(lwgyBaseBed.getStudentId());
            lwgyHotelHistory.setCreateBy(sysUser.getUsername());
            arrangementList.add(lwgyHotelHistory);
        }
        lwgyHotelHistoryService.saveBatch(arrangementList);//批量存储退宿记录
        List<LwgyBaseStudent> list = new ArrayList<>();
        LwgyBaseStudent lwgyBaseStudent;
        for (String string : strings) {
            if(oConvertUtils.isNotEmpty(string)){
                lwgyBaseStudent = new LwgyBaseStudent();
                lwgyBaseStudent.setId(string);
                lwgyBaseStudent.setStudentState("1");
                list.add(lwgyBaseStudent);
            }
        }
        lwgyBaseStudentService.updateBatchById(list);
    }*/

    @Override
    public void revertLeaveStu(String ids) {
        List<String> strings = Arrays.asList(ids.split(","));
        List<LwgyBaseStudent> list = new ArrayList<>();
        LwgyBaseStudent lwgyBaseStudent;
        for (String string : strings) {
            if(oConvertUtils.isNotEmpty(string)){
                lwgyBaseStudent = new LwgyBaseStudent();
                lwgyBaseStudent.setId(string);
                lwgyBaseStudent.setStudentState("0");
                list.add(lwgyBaseStudent);
            }
        }
        lwgyBaseStudentService.updateBatchById(list);
    }

    @Override
    public List<LwgyHotelHistory> leaveBedHistory(String ids) {
        QueryWrapper<LwgyBaseBed> queryWrapper;
        LwgyHotelHistory lwgyHotelHistory;
        List<LwgyHotelHistory> arrangementList = new ArrayList<>(15);
        List<String> list = Arrays.asList(ids.split(","));
        for (String studentId : list) {
            queryWrapper = new QueryWrapper<>();
            queryWrapper.select("id");
            queryWrapper.eq("student_id",studentId);
            LwgyBaseBed lwgyBaseBed = lwgyBaseBedMapper.selectOne(queryWrapper);
            lwgyHotelHistory = new LwgyHotelHistory();
            if(oConvertUtils.isNotEmpty(lwgyBaseBed)){
                String bedId = lwgyBaseBed.getId();
                lwgyHotelHistory.setBeforeBed(bedId);
            }
            lwgyHotelHistory.setPersonId(studentId);
            lwgyHotelHistory.setBehavior("leave_bed");
            arrangementList.add(lwgyHotelHistory);
        }
        return arrangementList;
    }

/* @Override
    public void cleanBedBatch(List<String> strings) {
        for (String string : strings) {
            LwgyHotelArrangement lwgyHotelArrangement
             = new LwgyHotelArrangement();
            lwgyHotelArrangement.setId(string);
            lwgyHotelArrangement.setStudentId("");
        }

        updateBatchById
    }*/

    @Override
    public Integer maxBed(LwgyBaseBed lwgyBed) {
        String roomId = lwgyBed.getRoomId();
        QueryWrapper<LwgyBaseApartment> queryWrapper = new QueryWrapper<>();
        queryWrapper.select("id","type");
        queryWrapper.eq("id",roomId);
        LwgyBaseApartment lwgyBaseApartment = lwgyBaseApartmentMapper.selectOne(queryWrapper);
        if(oConvertUtils.isEmpty(lwgyBaseApartment)){
            lwgyBaseApartment = new LwgyBaseApartment();
        }
        return lwgyHotelArrangementMapper.maxBed(lwgyBaseApartment);

    }

    @Override
    public List<LwgyHotelArrangement> queryStuBedByNumberList(List<String> numbers){
        return lwgyHotelArrangementMapper.queryStuBedByNumberList(numbers);
    }



    @Override
    public List<ImportStuHotelBed> selectBedByStuList(List<ImportStuHotelBed> stuList){
       return lwgyHotelArrangementMapper.selectBedByStuList(stuList);

    }

    @Override
    public List<ImportStuHotelBed> selectStudentIdList(List<ImportStuHotelBed> list){
       /* List<String> ids = new ArrayList<>(list.size());
        list.stream().forEach(item -> {
            if(oConvertUtils.isNotEmpty(item.getStudentNumber())){
                ids.add(item.getStudentNumber());
            }

        });*/
        List<ImportStuHotelBed> stuIdList = lwgyHotelArrangementMapper.selectStudentIdList(list);

        List<ImportStuHotelBed> bedIdList = lwgyHotelArrangementMapper.selectBedByStuList(list);
        list.stream().forEach(item -> {
            stuIdList.stream().forEach(item2 -> {
                if(oConvertUtils.isNotEmpty(item.getStudentNumber())
                        && item.getStudentNumber().equals(item2.getStudentNumber())){
                    item.setStudentId(item2.getStudentId());
                    item.setStudentClass(item2.getStudentClass());
                }
            });
            bedIdList.stream().forEach(item2 -> {
                if(oConvertUtils.isNotEmpty(item.getBuildingName())&& item.getBuildingName().equals(item2.getBuildingName())
                &&oConvertUtils.isNotEmpty(item.getRoomName())&& item.getRoomName().equals(item2.getRoomName())
                &&oConvertUtils.isNotEmpty(item.getBedName())&& item.getBedName().equals(item2.getBedName())
                ){
                    item.setBedId(item2.getBedId());
                    item.setAdminId(item2.getAdminId());
                }
            });
        });
        return list;
    }


    @Override
    public List<ImportStuHotel> selectStudentIdListX(List<ImportStuHotel> list){

        List<ImportStuHotel> stuIdList = lwgyHotelArrangementMapper.selectStudentIdListX(list);

        list.stream().forEach(item -> {
            stuIdList.stream().forEach(item2 -> {
                if(oConvertUtils.isNotEmpty(item.getStudentNumber())
                        && item.getStudentNumber().equals(item2.getStudentNumber())){
                    item.setStudentId(item2.getStudentId());
                    item.setStudentClass(item2.getStudentClass());
                }
            });
        });
        return list;
    }

    @Override
    public List<LwgyBaseBed> selectStuBedByStuId(String ids){

        List<String> idList = Arrays.asList(ids.split(","));
         return  lwgyHotelArrangementMapper.selectStuBedByStuId(idList);

    }

    @Override
    public List<LwgyBaseBed> selectStuBedById(String ids,String bedIds){


        List<LwgyBaseBed> list = new ArrayList<LwgyBaseBed>();
        if(oConvertUtils.isNotEmpty(ids)&&ids.length()>0){
            List<String> idList = Arrays.asList(ids.split(","));
            System.out.println(idList.size());
            List<LwgyBaseBed>  list1= lwgyHotelArrangementMapper.selectStuBedByStuId(idList);
            list.addAll(list1);
        }
        if(oConvertUtils.isNotEmpty(bedIds)&&bedIds.length()>0){
            List<String> bedList = Arrays.asList(bedIds.split(","));
            List<LwgyBaseBed>  list2= lwgyHotelArrangementMapper.selectStuBedByBedId(bedList);
            list.addAll(list2);
        }


        return list;
    }

    @Override
    public void cleanBedByStudentId(List<String> studentIdList) {
        if(oConvertUtils.listIsEmpty(studentIdList)){
            return;
        }
        lwgyHotelArrangementMapper.cleanBedByStudentId(studentIdList);
    }


    @Override
    public List<ImportHoildayStu> selectBedByHoildayStuList(List<ImportHoildayStu> stuList) {
        return lwgyHotelArrangementMapper.selectBedByHoildayStuList(stuList);
    }

    @Override
    public List<ImportHoildayStu> selectHoildayStudentIdList(List<ImportHoildayStu> list) {
        List<ImportHoildayStu> stuIdList = lwgyHotelArrangementMapper.selectHoildayStudentIdList(list);

        List<ImportHoildayStu> bedIdList = lwgyHotelArrangementMapper.selectBedByHoildayStuList(list);
        list.stream().forEach(item -> {
            stuIdList.stream().forEach(item2 -> {
                if(oConvertUtils.isNotEmpty(item.getStudentNumber())
                        && item.getStudentNumber().equals(item2.getStudentNumber())){
                    item.setStudentId(item2.getStudentId());
                    item.setStudentCollege(item2.getStudentCollege());
                    item.setStudentYear(item2.getStudentYear());
                    item.setStudentMajor(item2.getStudentMajor());
                    item.setStudentClass(item2.getStudentClass());
                    item.setRoomSex(item2.getRoomSex());
                }
            });
            bedIdList.stream().forEach(item2 -> {
                if(oConvertUtils.isNotEmpty(item.getBuildingName())&& item.getBuildingName().equals(item2.getBuildingName())
                        &&oConvertUtils.isNotEmpty(item.getRoomName())&& item.getRoomName().equals(item2.getRoomName())
                        &&oConvertUtils.isNotEmpty(item.getBedName())&& item.getBedName().equals(item2.getBedName())
                ){
                    item.setBedId(item2.getBedId());
                    item.setAdminId(item2.getAdminId());
                }
            });
        });
        return list;
    }
}
